layui.use(['element', 'table', 'laytpl', 'form'], function () {
    var $ = layui.$, form = layui.form;




    $( ".elderly" ).draggable({ helper:function () {
            return $(this);
        },revert: "invalid" });
    $( ".departments" ).droppable({
        drop: function( event, ui ) {
            $(this).append(ui.helper.removeAttr("style"));
        }
    });



    /*监听提交事件是否被点击*/
    form.on('submit(sub)', function () {
        var $departmentId = $(".departmentId");
        var data = new Array();
        $departmentId.each(function () {
            var departmentId = this.value;
            var $elderlyIds = $(this).parent().find('input[name="elderlyId"]');
            for (var i = 0; i < $elderlyIds.length; i++) {
                data.push('{"' + departmentId + '":' + $elderlyIds[i].value + '}');
            }
        });
        $.ajax({
            url: "/elderlyAllocation/save",
            data: {"alloactionData": data.toString()},
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if (data.code == "200") {
                    layer.msg("操作成功");
                }
                if (data.code == "0") {
                    layer.msg(data.message)
                }
            }
        });
        return false;
    });
});